package constant.milk.cashbook.main;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioButton;
import constant.milk.cashbook.R;
import constant.milk.cashbook.SuperActivity;

public class MainTypeActivity extends SuperActivity
{
	public static final String MAIN_TYPE_DATA = "MAIN_TYPE_DATA";
	
	private View outView;
	private View inView;
	private View moveView;
	private View fanView;
	private View balanceView;
	
	private RadioButton outRadio;
	private RadioButton inRadio;
	private RadioButton moveRadio;
	private RadioButton fanRadio;
	private RadioButton balanceRadio;
	
	private Button checkButton;
	
	private String typeStr;
	
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.main_type_activity);
		
		setTitle("메인타입");
		
		setFindViewId();
		setOnClick();
		setData();
	}

	@Override
	protected void setFindViewId()
	{
		outView = findViewById(R.id.mainTypeOutView);
		inView = findViewById(R.id.mainTypeInView);
		moveView = findViewById(R.id.mainTypeMoveView);
		fanView = findViewById(R.id.mainTypeFanView);
		balanceView = findViewById(R.id.mainTypeBalanceView);
		
		outRadio = (RadioButton) findViewById(R.id.mainTypeOutRadio);
		inRadio = (RadioButton) findViewById(R.id.mainTypeInRadio);
		moveRadio = (RadioButton) findViewById(R.id.mainTypeMoveRadio);
		fanRadio = (RadioButton) findViewById(R.id.mainTypeFanRadio);
		balanceRadio = (RadioButton) findViewById(R.id.mainTypeBalanceRadio);
		
		checkButton = (Button) findViewById(R.id.checkButton);
	}

	@Override
	protected void setOnClick()
	{
		outView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				setOutRadio();
			}
		});
		
		inView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				setInRadio();
			}
		});
		
		moveView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				setMoveRadio();
			}
		});
		
		fanView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				setFanRadio();
			}
		});
		
		balanceView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				setBalanceRadio();
			}
		});
		
		checkButton.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				Intent intent = new Intent();
				intent.putExtra(MAIN_TYPE_DATA, typeStr);
				setResult(Activity.RESULT_OK, intent);
				finish();
			}
		});
	}

	@Override
	protected void setData()
	{
		Intent intent = getIntent();
		String data = intent.getStringExtra(MAIN_TYPE_DATA);
		
		if (data.equals(getString(R.string.out)))
		{
			setOutRadio();
		}
		else if (data.equals(getString(R.string.in)))
		{
			setInRadio();
		}
		else if (data.equals(getString(R.string.move)))
		{
			setMoveRadio();
		}
		else if (data.equals(getString(R.string.fan)))
		{
			setFanRadio();
		}
		else if (data.equals(getString(R.string.balance)))
		{
			setBalanceRadio();
		}
		else
		{
			setOutRadio();
		}
	}
	
	private void setOutRadio()
	{
		outRadio.setChecked(true);
		inRadio.setChecked(false);
		moveRadio.setChecked(false);
		fanRadio.setChecked(false);
		balanceRadio.setChecked(false);
		typeStr = getResources().getString(R.string.out);
	}
	
	private void setInRadio()
	{
		outRadio.setChecked(false);
		inRadio.setChecked(true);
		moveRadio.setChecked(false);
		fanRadio.setChecked(false);
		balanceRadio.setChecked(false);
		typeStr = getResources().getString(R.string.in);
	}
	
	private void setMoveRadio()
	{
		outRadio.setChecked(false);
		inRadio.setChecked(false);
		moveRadio.setChecked(true);
		fanRadio.setChecked(false);
		balanceRadio.setChecked(false);
		typeStr = getResources().getString(R.string.move);
	}
	
	private void setFanRadio()
	{
		outRadio.setChecked(false);
		inRadio.setChecked(false);
		moveRadio.setChecked(false);
		fanRadio.setChecked(true);
		balanceRadio.setChecked(false);
		typeStr = getResources().getString(R.string.fan);
	}
	
	private void setBalanceRadio()
	{
		outRadio.setChecked(false);
		inRadio.setChecked(false);
		moveRadio.setChecked(false);
		fanRadio.setChecked(false);
		balanceRadio.setChecked(true);
		typeStr = getResources().getString(R.string.balance);
	}

	@Override
	protected void tipButton()
	{
	}

}
